<?php

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
error_reporting(E_ERROR | E_PARSE);
if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}

//error_reporting(E_ALL);
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival['t'], "t", "json");
		
	cgi::both($g_cgival['callback'], "callback", "");
	$g_cgival['callback'] = string::un_html(string::un_script_code($g_cgival['callback']));
	
	cgi::both($g_cgival['pscreen'], "pscreen", 1);
	
	cgi::both($g_cgival['tag_id'], "tag_id", 0);
	
	$g_cgival['tag_id'] = intval($g_cgival['tag_id']);
	
	cgi::both($g_cgival['show_type'], "show_type", 0);
	
	$g_cgival['show_type'] = intval($g_cgival['show_type']);
	
	cgi::both($g_cgival['pcount'], "pcount", 20);
	$g_cgival['pcount'] = intval($g_cgival['pcount']);
	if($g_cgival['pcount'] > 100) $g_cgival['pcount']=100;
	
	cgi::both($g_cgival['uid'], "uid", 0);
	
	cgi::both($g_cgival['show_del'], "show_del", 0);
	cgi::both($g_cgival['type'], "type", "common");
	cgi::both($g_cgival['show_mblog_tag'], "show_mblog_tag", 0);
	cgi::both($g_cgival['order'], "order", "time");
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	
	
	$show_mblog_tag = $g_cgival['show_mblog_tag'];
	$show_del = $g_cgival['show_del'];
	$admin_uid = $_SESSION["admin"]["uid"];//后台超管设置权限
	$order = $g_cgival['order'];
	
	$admin_uid = user_info::check_super_admin($uid);
	if($admin_uid)
	{
		$show_del = 1;
	}
	$tag_id = $g_cgival['tag_id'];
	$topic_id = $g_cgival["topic_id"] = $config["current_site_id"];
	$pcount = $g_cgival['pcount'];
	$show_type = $g_cgival['show_type'];
	$uid = $g_cgival['uid'];
	
	$type = $g_cgival['type'];
	$db_mblog_pic_content = new db_mblog_pic_content();
	$db_mblog_user_love = new db_mblog_user_love();
	
	$mod_mblog = new mod_mblog();
	$get_pubu_info = $mod_mblog->get_pic_pubu_info($g_cgival["pscreen"],$pcount,$type,$topic_id,$show_type,$uid,$order,$tag_id);
	$list = $get_pubu_info["list"];
	
	if(count($list) < $pcount)
	{
		$g_show["is_finish"] = 1;
	}
	$db_user_info = new db_user_info();
	$start_value = "";
	foreach($list as $value)
	{
		$div_list[] = $value["html"];
		
	}
	if(!$div_list)
	{
		$div_list = array();
	}
	$g_show["data"] = join("",$div_list);
	$g_show["start_value"] = $start_value;
	
	
}
try {
	
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = "";
	
	
} 
catch (Exception $e) 
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
	
}
show_pro();

exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	if ($g_cgival['t'] == "serialize")
	{
		echo serialize($g_show);
	}
	elseif ($g_cgival['t'] == "json")
	{
		echo output::json("json", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "jsonp")
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "perl")
	{
		$string = php_to_perl::php_array_to_perl_hash($g_show);
		$string = mb_convert_encoding($string, "GBK", "UTF-8");
		echo $string;
	}
	elseif($g_cgival['t'] == "iframe")
	{
		header("location:{$g_cgival['link']}");
	}
	else
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
}

